#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

class Solution {
public:
    int numEquivDominoPairs(vector<vector<int>>& dominoes) {
        int result=0;
        map<vector<int>,int> M;
        for(int i = 0;i<dominoes.size();++i){
            vector<int> temp = dominoes[i];
            reverse(temp.begin(),temp.end());
            if(M.find(dominoes[i])==M.end()&&M.find(temp)==M.end()){
                M[dominoes[i]] = 1;
            }
            else{
                if(M.find(dominoes[i])!=M.end()){
                    ++M[dominoes[i]];
                }
                else if(M.find(temp)!=M.end()){
                    ++M[temp];
                }
            }
        }
        for(auto i = M.begin();i!=M.end();++i){
            if(i->second>1){
                result += (i->second-1)+0.5*(i->second-1)*(i->second-2);
            }
        }
        return result;
    }
};

int main(){
    vector<vector<int>> nums = {{1,2},{2,1},{1,2},{5,6}};
    Solution S;
    cout<<S.numEquivDominoPairs(nums)<<endl;


}

